package com.elaticsearch.test;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;

/**
 * @author:左泽林
 * @date:日期:2021-08-28-时间:15:30
 * @message:
 */
public class Delete {
    public static void main(String[] args) {
        //创建ES客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("172.20.17.43",9200,"http"))
        );

        //关闭ES客户端
        try {
            DeleteIndexRequest user = new DeleteIndexRequest("dex");
            AcknowledgedResponse delete = esClient.indices().delete(user, RequestOptions.DEFAULT);

            //响应状态
            System.out.println("===============操作结果==============");
            System.out.println("删除结果"+delete.isAcknowledged());
            System.out.println("===============操作结果==============");

            esClient.close();
        }catch (Exception e){
            System.out.println(e);
        }
    }
}
